/*
 * File:   10422.cpp
 * Author: xerxes
 *
 * Created on September 16, 2011, 7:39 PM
 *
 * I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait(double seconds) {
    double endtime = clock()+(seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}

vector< string > ss(5, ""), final(5, "");

inline void Print(vector<string> vs) {

    fo(i, 0, 5) {
        cout << vs[i] << "\n";
    }
    cout << "\n";
    return;
}

inline void Read() {

    fo(i, 0, 5) {
        getline(cin, ss[i]);
    }
}

int mr[8] = {-2, -2, +2, +2, -1, -1, +1, +1};
int mc[8] = {-1, +1, -1, +1, -2, +2, -2, +2};
map< vector<string>, int > mp;

inline void Gen() {
    queue< vector<string> > q;
    q.push(final);
    mp[ final ] = 0;
    while (q.empty() == false) {
        vector<string> father = q.front();
        int move = mp[ father ];
        //        Print(father);
        //        printf("And MOVE %d\n",move);wait(1);

        q.pop();
        if (move >= 10)continue;
        int sx, sy;

        fo(i, 0, 5) {

            fo(j, 0, 5) {
                if (father[i][j] == ' ') {
                    sx = i;
                    sy = j;
                    goto L;
                }
            }
        }

L:
        fo(i, 0, 8) {
            int tr = sx + mr[i];
            int tc = sy + mc[i];
            if (tr < 0 || tc < 0 || tr >= 5 || tc >= 5)continue;
            swap(father[sx][sy], father[tr][tc]);
            if (!mp.count(father)) {
                q.push(father);
                mp[ father ] = move + 1;
            }
            swap(father[sx][sy], father[tr][tc]);
        }

    }

}

inline void Proc() {
    if (!mp.count(ss)) {
        puts("Unsolvable in less than 11 move(s).");
    } else {
        printf("Solvable in %d move(s).\n", mp[ss]);
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "rt", stdin);
#endif
    final[0] = "11111";
    final[1] = "01111";
    final[2] = "00 11";
    final[3] = "00001";
    final[4] = "00000";
    Gen();

    int cases = 1;
    for (CI(cases), getchar(); cases; --cases) {
        Read();
        Proc();
    }

    return 0;
}


